<?php

namespace app\modules\controllers;
use yii;
use yii\web\Controller;
use app\modules\models\Admin;

/**
 * Default controller for the `admin` module
 */
class PublicController extends Controller
{
	public $layout=false;
    /**
     * Renders the index view for the module
     * @return string
     */
    public function actionLogin()
    {

       $model=new Admin;

        if(YII::$app->request->isPost){
            $post=YII::$app->request->post();

            if($model->login($post)){
                $this->redirect(['default/index']);
                YII::$app->end();
            }
        }
        
        if(YII::$app->session['admin']['isLogin']){
            $this->redirect(['default/index']);
        }
        return $this->render('Login',['model'=>$model]);
    }
    public function actionSeekpassword()
    {

        $model=new Admin;
        if(Yii::$app->request->isPost){
            $post=YII::$app->request->post();
             
            if($model->seekPass($post)){

                Yii::$app->session->setFlash('info','电子邮件已经发送成功，请查收');
            }

        }

        return $this->render('Seekpassword',['model'=>$model]);
    }

   public function actionLogout()
    {

         
       YII::$app->session->removeALL();
       if(!isset(YII::$app->session['admin']['isLogin'])){
        $this->redirect(['public/login']);
        //$this->redirect(['admin/public/login']);
        //$this->redirect(['default/index']);
        
        YII::$app->end();
       }else{
        $this->goback();
       }
    }

    public function actionLigout()
    {

        $this->redirect(['public/login']);

    }



}
